import allow from '../images/allow.png'

export function polylineDecompressionDriving (polylines: number[]) {
  let coors: number[][] = [polylines]
  let kr = 1000000
  for (let i = 0; i < coors.length; i++) {
    for (let j = 2; j < coors[i].length; j++) {
      coors[i][j] = +(coors[i][j - 2]) + +(coors[i][j]) / kr
    }
  }

  // 定义新数组，将coors中的数组合并为一个数组
  let coorsArr: number[] = []
  let _points: { latitude: number, longitude: number }[] = []
  for (let i = 0; i < coors.length; i++) {
    coorsArr = coorsArr.concat(coors[i])
  }

  //将解压后的坐标放入点串数组_points中
  for (let i = 0; i < coorsArr.length; i += 2) {
    _points.push({latitude: coorsArr[i], longitude: coorsArr[i + 1]})
  }

  let polyline = {
    width: 8,
    points: _points,
    color: '#54b471',
    dottedLine: false,
    arrowLine: true,
    arrowIconPath: allow,
    borderColor: '#306e50',
    borderWidth: 3,
  }

  return polyline
}

// function getStepPolyline(step: Step) {
//   let coors: number[][] = [];
//   let colorArr = ['#1aad19', '#10aeff', '#d84e43']
//   let _dottedLine = true
//   if (step.mode == 'WALKING' && step.polyline) {
//     coors.push(step.polyline);
//     _dottedLine = false
//   } else if (step.mode == 'TRANSIT' && step.lines[0].polyline) {
//     coors.push(step.lines[0].polyline);
//   } else {
//     return null
//   }
//   //坐标解压（返回的点串坐标，通过前向差分进行压缩）
//   let kr = 1000000;
//   for (let i = 0 ; i < coors.length; i++){
//     for (let j = 2; j < coors[i].length; j++) {
//       coors[i][j] = Number(coors[i][j - 2]) + Number(coors[i][j]) / kr;
//     }
//   }
//   //定义新数组，将coors中的数组合并为一个数组
//   let coorsArr: number[][] = [];
//   let _points: {latitude: number[], longitude: number[]}[] = [];
//   for (let i = 0 ; i < coors.length; i ++){
//     coorsArr = coorsArr.concat(coors[i]);
//   }
//
//   //将解压后的坐标放入点串数组_points中
//   for (let i = 0; i < coorsArr.length; i += 2) {
//     _points.push({ latitude: coorsArr[i], longitude: coorsArr[i + 1] })
//   }
//   if (!stepPolyline.colorIndex) {
//     stepPolyline.colorIndex = 0
//   }
//   let colorIndex = stepPolyline.colorIndex % colorArr.length
//   setStepPolyline(() => ({
//     colorIndex: ++stepPolyline.colorIndex
//   }))
//   let polyline = {
//     width: 7,
//     points: _points,
//     color: colorArr[colorIndex],
//     dottedLine: _dottedLine,
//     arrowLine: true, // 带箭头的线, 开发者工具暂不支持该属性
//     borderColor: '#fff',
//     borderWidth: 1
//   }
//   return polyline
// }
